///////////////////////////////////////////////////////////////////////
//  CS 3715 (Winter 2012), Final Project                      		 //
//  Program File Name: OrderServlet.java                           	 //
//       Student Name: Jonathan Hart-Wall, Kenny Hardiman            //
//         Login Name: jcwhw1, kch004                                //
//              MUN #: 200933455, 200930253    						 //
///////////////////////////////////////////////////////////////////////

package ca.FMP;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import ca.FMP.DBAccess;

/*
 * OrderServlet Class, used to receive HTTPrequests from the Banner page, and sends XML to Order page 
 */
public class OrderServlet extends HttpServlet {

	/*
	 * @see
	 * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
	 * , javax.servlet.http.HttpServletResponse) doGet method that recieves
	 * HTTPRequests, and sends XML
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		/*
		 * Sets response type to xml. Sets PizzaPlace to parameter of pp. Sets
		 * pizzas to array of order split by blank space
		 */
		response.setContentType("text/xml");
		PrintWriter out = response.getWriter();
		String PizzaPlace = request.getParameter("pp");

		out.println("<?xml version='1.0'?>");

		/*
		 * XML response, that returns PizzaPlace and Name of PizzaPlace
		 */
		for (int i = 0; i < DBAccess.database.db.size(); i++) {
			if (DBAccess.database.db.get(i).getName().equals(PizzaPlace)) {
				out.println("<PizzaPlace> \n");
				out.println("<Name>" + DBAccess.database.db.get(i).getName()
						+ "</Name> \n");
				out.println("</PizzaPlace> \n");
			}
		}
	}
}